package com.homevip.core.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import com.homevip.util.PropUtil;

/**
 * 全局变量
 * 
 * @author ll
 */
public class Global {

	public static String ServerInstance; // 服务实例编号
	public static String ServerTaskInstance; // 可运行任务的机器编号
	public static String WebPath;
	public static String FilePath;

	public static String mail_from;
	public static String mail_user;
	public static String mail_password;
	public static String smtp_server;
	public static String MailSign;
	
	/**
	 * 读取配置
	 * 
	 * @throws IOException
	 */
	public static boolean load() {

		String strFileName = "properties/global.properties";
		Properties ps = new Properties();
		FileInputStream istream = null;
		try {
			PropUtil.getInstance();
			istream = new FileInputStream(PropUtil.getInstance().getSystemPath(strFileName));
			ps.load(istream);
			istream.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("init falie:" + strFileName);
			Thread.interrupted();
			return false;
		} finally {
			if (istream != null) {
				try {
					istream.close();
				} catch (Throwable ignore) {
				}
			}
		}

		ServerInstance = ps.getProperty("server_instance");
		if (null == ServerInstance)
			ServerInstance = "signle"; // 默认单例
		
		ServerTaskInstance = ps.getProperty("server_task_instance");

		// path
		WebPath = ps.getProperty("web_path");
		FilePath = ps.getProperty("file_path");

		// mail
		mail_from = ps.getProperty("mail_from");
		mail_user = ps.getProperty("mail_user");
		mail_password = ps.getProperty("mail_password");
		smtp_server = ps.getProperty("smtp_server");
		MailSign = ps.getProperty("mail_sign");

		return true;
	}

	/**
	 * 测试
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		System.out.println("Global load...");
		Global.load();
		System.out.println("Global.WebPath: " + Global.WebPath);
	}
}
